﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Vit.Mvc.Extensions
{
    public static class RouteValueDictionaryExtensions
    {
        public static void Merge(this RouteValueDictionary routes, string key, object val)
        {
            if (routes == null || string.IsNullOrEmpty(key))
                return;
            if (routes.ContainsKey(key))
                routes[key] = val;
            else
                routes.Add(key, val);
        }

        public static void Merge(this RouteValueDictionary to, RouteValueDictionary from)
        {
            if (from == null || to == null)
                return;
            foreach (KeyValuePair<string, object> kvp in from)
            {
                if (to.ContainsKey(kvp.Key))
                    to[kvp.Key] = kvp.Value;
                else
                    to.Add(kvp.Key, kvp.Value);
            }
        }
    }
}
